﻿namespace MeiTool.Log
{
    /// <summary>
    /// 日志帮助类
    /// </summary>
    public class LogHelp
    {
        /// <summary>
        /// 日志保存路径
        /// </summary>
        public string LogPath { get; set; }
        /// <summary>
        /// 是否使用默认保存路径，默认保存路径为：程序运行路径/Logs
        /// </summary>
        public bool IsDefaultPath { get; set; }
        /// <summary>
        /// 日志路径是否根据月份新建文件夹。默认为是
        /// </summary>
        public bool IsLogPathMonthDay { get; set; }
        public LogHelp(bool isDefaultPath = true, bool isLogPathMonthDay = true, string logPath = "")
        {
            LogPath = logPath;
            IsDefaultPath = isDefaultPath;
            IsLogPathMonthDay = isLogPathMonthDay;
            if (IsDefaultPath)
            {
                LogPath = AppDomain.CurrentDomain.BaseDirectory + $"\\Logs";
            }
            if (IsLogPathMonthDay)
            {
                LogPath = LogPath + $"\\{DateTime.Now:yyyyMMdd}\\";
            }
        }

        /// <summary>
        /// 常规日志
        /// </summary>
        /// <param name="logMessage">日志内容</param>
        public void InfoLog(string logMessage)
        {
            if (string.IsNullOrWhiteSpace(logMessage))
            {
                return;
            }
            LogMethod.WriteTxtData(logMessage, "Info", LogPath);
        }
        /// <summary>
        /// 警告日志
        /// </summary>
        /// <param name="logMessage">日志内容</param>
        public void WarningLog(string logMessage)
        {
            if (string.IsNullOrWhiteSpace(logMessage))
            {
                return;
            }
            LogMethod.WriteTxtData(logMessage, "Warning", LogPath);
        }
        /// <summary>
        /// 错误日志
        /// </summary>
        /// <param name="logMessage">日志内容</param>
        public void ErrorLog(string logMessage)
        {
            if (string.IsNullOrWhiteSpace(logMessage))
            {
                return;
            }
            LogMethod.WriteTxtData(logMessage, "Error", LogPath);
        }
        /// <summary>
        /// 致命日志
        /// </summary>
        /// <param name="logMessage">日志内容</param>
        public void FatalLog(string logMessage)
        {
            if (string.IsNullOrWhiteSpace(logMessage))
            {
                return;
            }
            LogMethod.WriteTxtData(logMessage, "Fatal", LogPath);
        }

    }
}